package test.h0820;

import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringJoiner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 找朋友
 * @date 2024/8/20 1:21
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] friends = new int[n];
        for (int i = 0; i < n; i++) {
            friends[i] = sc.nextInt();
        }
        getRes(friends, n);
    }

    private static void getRes(int[] friends, int n) {
        //存储元素值和下标值，每次遇到弹出当作，将将要加入的元素下标加入结果集
        LinkedList<int[]> stack = new LinkedList<>();
        int[] ans = new int[n];
        int k = 0;

        //这道题目的下标就是用来在弹出栈的时候利用这个下标，修改结果集。意思就是修改哪个下标结果
        stack.addLast(new int[]{friends[0], 0});
        for (int i = 1; i < n; i++) {
            while (!stack.isEmpty() && friends[i] > stack.peekLast()[0]) {
                int[] temp = stack.removeLast(); //弹出栈的元素
                ans[temp[1]] = i;  //弹出栈最近的那个身高大于他的人下标就是i
            }
            stack.addLast(new int[]{friends[i],i});
        }
        StringJoiner joiner = new StringJoiner(" ");
        for (int i : ans) {
            joiner.add(i + "");
        }
        System.out.println(joiner);
    }
}
